package com.ts.proj.service.impl;

import com.ts.proj.entity.TransportunitEntity;
import com.ts.proj.repository.TransportunitRepository;
import com.ts.proj.service.TransportunitService;
import com.ts.util.PageData;

import com.ts.base.service.impl.CommonServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


//说明 字符串：，作为替换字符串 LOWERTransportunit                Transportunit

@Service
public class TransportunitServiceImpl extends CommonServiceImpl<TransportunitEntity>  implements TransportunitService {

    @Autowired
    private TransportunitRepository transportunitRepository;

    @Override
    public List<TransportunitEntity> findAll(PageData pageData, Integer start, Integer length) {
        Specification<TransportunitEntity> sp = this.getSpecification(pageData,TransportunitEntity.class);
        Sort sort = new Sort(Sort.Direction.ASC,"id");
        Pageable pageable = new PageRequest(start, length, sort);
        return transportunitRepository.findAll(sp,pageable).getContent();
    }

    @Override
    public long count(PageData pageData) {
        Specification<TransportunitEntity> sp = this.getSpecification(pageData,TransportunitEntity.class);
        return transportunitRepository.count(sp);
    }

    @Override
    public boolean deleteByIds(Iterable<TransportunitEntity> iterable) {
        transportunitRepository.deleteInBatch(iterable);
        return false;
    }

    @Override
    public List<TransportunitEntity> saveAll(List<TransportunitEntity> entities) {
        return transportunitRepository.saveAll(entities);
    }

    @Override
    public List<TransportunitEntity> findAllById(Integer[] ids) {
        List<TransportunitEntity> list = transportunitRepository.findAllById(Arrays.asList(ids));
        if(list.size()==0){
            TransportunitEntity entity = new TransportunitEntity();
            list.add(entity);
        }
        return list;
    }

    @Override
    public boolean deleteAll() {
		transportunitRepository.deleteAll();
        return false;
    }
}